package main

import (
	"fmt"
	"reflect"
	"runtime"
	"time"
)

func foo() {
	fmt.Println("foo is running !")
	time.Sleep(time.Second * 2)
}

func bar() {
	fmt.Println("bar is running !")
	time.Sleep(time.Second * 2)
}
func GetCounter(f func()) func() {
	var i int = 0
	return func() {
		f()
		i++
		fn := runtime.FuncForPC(reflect.ValueOf(f).Pointer()).Name()
		fmt.Printf("%s函数执行的次数为：%d次。\n", fn, i)
	}
}

func main() {
	foo := GetCounter(foo)
	foo()
}
